package org.example.travel_web.controller.admin;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.example.travel_web.dto.PageResult;
import org.example.travel_web.dto.user.PageReq;
import org.example.travel_web.dto.user.PageResp;
import org.example.travel_web.dto.user.UserReq;
import org.example.travel_web.entity.UserET;
import org.example.travel_web.service.UserService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/user")
@Tag(name = "用户管理")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping
    @Operation(summary = "用户分页")
    public PageResult<PageResp> userPageResult(@Valid PageReq req) {
        return userService.pageResult(req);
    }

    @GetMapping("/{uid}")
    @Operation(summary = "查询用户")
    @Parameter(name = "uid", description = "用户id", required = true, in = ParameterIn.PATH)
    public UserET getUser(@PathVariable Long uid) {
        return userService.getById(uid);
    }

    @PostMapping
    @Operation(summary = "新增用户")
    public void addUser(@Valid UserReq req) {
        userService.addUser(req);
    }

    @PutMapping
    @Operation(summary = "修改用户")
    public void updateUser(@Valid UserReq req) {
        userService.updateUser(req);
    }

    @DeleteMapping
    @Operation(summary = "删除用户")
    @Parameter(name = "ids", description = "用户id列表", required = true, in = ParameterIn.QUERY)
    public void delUser(@RequestParam Long[] ids) {
        userService.delUser(ids);
    }
}
